import {getOrdersell} from '../../utils/api'
Page({
  data: {
    currentTab: 5,
    orderList: [
      
    ]
  },

  // 切换订单状态标签
  switchTab(e) {
    const index = e.currentTarget.dataset.index;
    this.setData({
      currentTab: index,
    });
    wx.showLoading({
      title: '加载中...', 
      mask: true, 
    });
    this.getOrderList(index);
  },

  // 获取订单列表
  async getOrderList(status) {
    
    const {data:res} = await getOrdersell(status)
    console.log(res)
    if(res.data.code != 200) return setTimeout(() => {
      wx.hideLoading();
      wx.showToast({
        title: '加载数据出错',
        icon: 'none',
        duration: 1000
      });
    }, 2000);
    res.data.data.map(item=>{
      item.url = JSON.parse(item.url)[0]
    })
    setTimeout(() => {
      wx.hideLoading();
      this.setData({
        orderList:res.data.data
     })
      wx.showToast({
        title: '加载完成',
        icon: 'success',
        duration: 1500
      });
    }, 500);
    
    
  },
  //去发货
  viewDeliver(e){
    wx.navigateTo({
      url: `/pages/delivery/delivery?id=${e.currentTarget.dataset.id}`,
    })
  },
  onLoad() {
    this.getOrderList(5);
  }
});